using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;

public partial class Admin_AddProvince : System.Web.UI.Page
{
    #region Variable
    protected long Id
    {
        get
        {
            object o = ViewState["Id"];
            if (o != null)
                return (long)o;
            return long.MinValue;
        }
        set
        {
            ViewState["Id"] = value;
        }
    }

    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        if (Request.QueryString["id"] != null)
        {
            this.Id = long.Parse(Request.QueryString["id"].ToString());
        }
        LoadData();
        LoadCurent();
    }
    #region LoadCurent
    private void LoadCurent()
    {
        HtmlGenericControl ulAdmin = (HtmlGenericControl)Master.FindControl("ulAdmin");
        ulAdmin.Attributes.Add("class", "current");
        HtmlGenericControl liSubShow = (HtmlGenericControl)Master.FindControl("liSubShowAdd");
        liSubShow.Attributes.Add("class", "sub_show");
        HtmlControl divSelectSub = (HtmlControl)Master.FindControl("divSelectSub");
        divSelectSub.Attributes.Add("class", "select_sub show");
    }
    #endregion
    #region VoidSave and Reset
    protected void btnsave_Click(object sender, EventArgs e)
    {
        ADESSA.Entities.Province _Province = new ADESSA.Entities.Province();
        if (this.Id != long.MinValue && this.Id != 0)
        {
            //_User = UserService.GetUser(this.Id);
            _Province = ProvinceService.GetProvince(this.Id);
        }
        _Province.Title = txtProvince.Value.Trim();
        if (this.Id != long.MinValue && this.Id != 0)
        {

            //UserService.UpdateUser(_User);
            ProvinceService.UpdateProvince(_Province);
            Response.Redirect("Province.aspx");

        }
        else
        {
            //UserService.CreateUser(_User);
            ProvinceService.CreateProvince(_Province);
            Response.Redirect("Province.aspx");
        }
    }
    protected void btnexit_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.ToString());
    }
    #endregion
    #region LoadData
    private void LoadData()
    {
        ADESSA.Entities.Province _Province = new ADESSA.Entities.Province();
        if (this.Id != long.MinValue && this.Id != 0)
        {
            //_User = UserService.GetUser(this.Id);
            _Province = ProvinceService.GetProvince(this.Id);
            if (_Province != null)
            {
                txtProvince.Value = _Province.Title;
            }
        }
    }
    #endregion
}
